let starBtn = document.querySelector(".starBtn");
let prizeCell = document.querySelectorAll(".drawBox div:not(.starBtn)");
let get = document.querySelector(".get");
let index = 0;
let targetIndex = 84;
let timer;
let second = 200;
let isRun = true;



starBtn.addEventListener("click", function () {
    if (isRun) {
        inrun = false;
        run();
    }
})

function run () {

    setTimeout(function () {

        // 创建个变量存放随机数，用来控制类的添加   原本的index用来控制次数
        let nowIndex = Math.ceil(Math.random() * index + 3);

        prizeCell.forEach(function (item) {
            item.classList.remove("active");
        })
        prizeCell[nowIndex % 8].classList.add("active");
        if (index < targetIndex) {
            run();
        }

        // getAttribute获取src字符串再赋值给空标签里面的src
        get.firstElementChild.src = prizeCell[nowIndex % 8].firstElementChild.getAttribute("src");

        // 同上只是换了个方法
        get.lastElementChild.innerHTML = prizeCell[nowIndex % 8].lastElementChild.innerHTML;

        index++;
        if (second > 20 && index < 24) {
            second -= 20;
        } else if (index > 74) {
            second += 50;
        } else {
            inRun = true;
        }
    }, second)
}